<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ include file="/common/taglibs.jsp"%>
<script type="text/javascript">
	$("#Wsshare_datagrid_list").datagrid({
		url : '${ctx}/Wsshare/Wsshare_datagridlist.do',
		pagination : true,
		fit : true,
		border : true,
		idField : 'id',
		pageSize : 50,
		rownumbers : true,
		pageList : [ 5, 10, 20, 30, 50, 100 ],
		sortName : 'Wssharename',
		sortOrder : 'desc',
		checkOnSelect : true,
		selectOnCheck : true,
		columns : [ [ {
			field : 'id',
			title : '编号',
			width : 150,
			checkbox : true
		}, {
            field : 'workflowtype',
            title : '流程类型',
            width : 150,
            sortable : true
        }, {
			field : 'wsnamenow',
			title : '主文书',
			width : 150,
			sortable : true
		}, {
			field : 'wscodenow',
			title : '主文书代码',
			width : 150,
			sortable : true
		}, {
			field : 'wscolumenow',
			title : '主文书列名',
			width : 150,
			sortable : true
		} , {
			field : 'wsnameto',
			title : '共享文书',
			width : 150,
			sortable : true
		}, {
			field : 'wscodeto',
			title : '共享文书代码',
			width : 150,
			sortable : true
		}, {
			field : 'wscolumnto',
			title : '共享文书列名',
			width : 150,
			sortable : true
		}, {
			field : 'orderno',
			title : '序号',
			width : 150,
			sortable : true
		}] ],
		toolbar : [ {
			text : '添加',
			iconCls : 'icon-add',
			handler : function() {
				$("#Wsshareadd_dialog").dialog('open');
				$("#Wsshareadd_Form input").val('');
			}
		}, '-', {
			text : '编辑',
			iconCls : 'icon-edit',
			handler : function() {
				Wsshareedit();
			}
		}, '-', {
			text : '删除',
			iconCls : 'icon-remove',
			handler : function() {
				Wsshareremove();
			}
		}, '-', {
			text : '开始查询',
			iconCls : 'icon-remove',
			handler : function() {
				WssharesearchFun();
			}
		}, '-', {
			text : '重置查询',
			iconCls : 'icon-remove',
			handler : function() {
				WssharecleanFun();
			}
		} ]
	});

	function WssharesearchFun() {
		$("#Wsshare_datagrid_list").datagrid('load',
				$.serializeObject($('#WssharesearchForm')));
	}

	function WssharecleanFun() {
		$("#WssharesearchForm input").val('');
		$("#Wsshare_datagrid_list").datagrid('load', {});
	}
	
	function Wsshareedit(){
		var datagrid = $("#Wsshare_datagrid_list");
		var rows = datagrid.datagrid('getChecked');
		console.info(rows);
		var ids = "";
		if(rows.length == 0){
			$.messager.show({
				title:'提示',
				msg:'请您选择一条数据来做编辑操作！'
			});
		}
		if(rows.length > 1){
			$.messager.show({
				title:'提示',
				msg:'只能选择一条数据来做编辑操作！'
			});
		}
		if(rows.length == 1){
			var dynamic_dialog  = $("<div/>").dialog({
			    title: '用户编辑',
			    fit:true,
			    closed: false,
			    cache: false,
			    href: '${ctx}/Wsshare/editTo.do',
			    modal: true,
			    buttons:[{
					text : '编辑',
					iconCls: 'icon-add',
					handler : function() {
						$.serializeObject($('#WsshareEdit_edit_form'));
						$('#WsshareEdit_edit_form').form('submit',{
							url:'${ctx}/Wsshare/edit.do',
							onSubmit:function(){
							},
							success:function(data){
								var obj = $.parseJSON(data);
								if(obj.success){
									dynamic_dialog.dialog('close');
									datagrid.datagrid('updateRow',{
										index: datagrid.datagrid('getRowIndex',rows[0]),	// index start with 0,在第一行插入数据
										row: obj.obj
									});
								}
								$.messager.show({
									title:'提示',
									msg:obj.msg
								});
							}
						});
					}
				} ],
				onClose:function(){
					$(this).dialog('destroy');
				},
				onLoad:function(){
					$("#WsshareEdit_edit_form").form('load',rows[0]);
				}
			    
			});
		}
	}

	function Wsshareremove() {
		var datagrid = $("#Wsshare_datagrid_list");
		var rows = datagrid.datagrid('getChecked');
		var ids = [];
		if(rows.length > 0){
			$.messager.confirm('确认','确认要要删除吗？',function(r){
			    if (r){
			    	for(var i=0;i<rows.length;i++){
						ids.push(rows[i].id);
					}
					$.ajax({
						url:'${ctx}/Wsshare/del.do',
						data:{
							ids:ids.join(',')
						},
						dataType:'json',
						success:function(data){
							datagrid.datagrid('load');
							datagrid.datagrid('unselectAll');//使全部的行形成未選中狀態
							$.messager.show({
								title:'提示',
								msg:data.msg
							});
						}
					});
			    }
			});
		}else{
			$.messager.show({
				title:'提示',
				msg:'请至少选择一行来做删除操作！'
			});
		}
	}
	
	   $('#workflowtypeshare').combobox({
	        url:'${ctx}/dd/getTreeMenu?id=402880e459c8e16d0159c9405f35001a',
	        method:'get',
	        valueField:'value',
	        textField:'text',
	        panelHeight:'100',
	        editable:false,
	        required:true,
            onSelect: function(rec){
               var aa=rec.id;
               $('#wsnamenowpre').combobox('clear');
               $('#wsnametopre').combobox('clear');
                $('#wscolumenow').combobox('clear');
                $('#wscolumnto').combobox('clear');
               var url = '${ctx}/dd/getTreeMenu?id='+aa;
               $('#wsnamenowpre').combobox('reload', url);
               $('#wsnametopre').combobox('reload', url);
           }
	    });
	
	
	   $('#wsnamenowpre').combobox({
	        //url:'${ctx}/dd/getTreeMenu?id=402880e65590f4b90155910794000000',
	        method:'get',
	        valueField:'value',
	        textField:'text',
	        panelHeight:'100',
	        editable:false,
	        required:true,
	        onSelect: function(rec){	        	
	        	var aa=rec.value;
	        	var bb=rec.text;
	        	$('#wsnamenow').val(bb);
	        	$('#wscodenow').val(aa);	   
	        	 $('#wscolumenow').combobox('clear');
		            var url = '${ctx}/Wsshare/getcolumns?wstype='+aa;
		            $('#wscolumenow').combobox('reload', url);
	        }
	    });
	   
	   $('#wsnametopre').combobox({
	       // url:'${ctx}/dd/getTreeMenu?id=402880e65590f4b90155910794000000',
	        method:'get',
	        valueField:'value',
	        textField:'text',
	        panelHeight:'100',
	        editable:false,
	        required:true,
	        onSelect: function(rec){	        	
	        	var aa=rec.value;
	        	var bb=rec.text;
	        	$('#wsnameto').val(bb);
	        	$('#wscodeto').val(aa);
	        	 $('#wscolumnto').combobox('clear');
		            var url = '${ctx}/Wsshare/getcolumns?wstype='+aa;
		            $('#wscolumnto').combobox('reload', url);
	        }
	    });
	   	   	   
</script>

<div class="easyui-layout" data-options="fit : true,border : false">
	<div data-options="region:'north',title:'条件筛选区',border:false" style="height:100px;overflow:hidden;">
		<form id="WssharesearchForm">
			<table class="table">
					<tr>
				<th>主文书：</th>
				<td><input type="text" name="wsnamenow" /></td>
				<th>共享文书：</th>
				<td><input type="text" name="wsnameto" /></td>
			</tr>
			</table>
		</form>
	</div>
	<div data-options="region:'center',border:false">
		<table id="Wsshare_datagrid_list"></table>
	</div>
</div>
<div id="Wsshareadd_dialog" class="easyui-dialog"
	style="width: 1100px;height:700px;"
	data-options="collapsible:true,maximizable:true,resizable:true,closable:true,closed:true,modal:true,title:'添加同步文书',buttons:[{
				text : '添加',
				iconCls: 'icon-add',
				handler : function() {
					$.serializeObject($('#Wsshareadd_Form'));
					$('#Wsshareadd_Form').form('submit',{
						url:'${ctx}/Wsshare/save.do',
						onSubmit:function(){
							return $('#Wsshareadd_Form').form('validate');
						},
						success:function(data){
							var obj = $.parseJSON(data);
							if(obj.success){
								//$('#Wsshare_datagrid_list').datagrid('load')此方法还得发送一次查询的请求效率较低，所以要用下面的方法替代
								$('#Wsshare_datagrid_list').datagrid('insertRow',{
									index: 0,	// index start with 0,在第一行插入数据
									row: obj.obj
								});
								$('#Wsshareadd_dialog').dialog('close');
							}
							$.messager.show({
								title:'提示',
								msg:obj.msg
							});
						}
					});
				}
			} ]">
	<form id="Wsshareadd_Form" method="post">
		<table class="table">
			<tr colspan="2">
				<th>序号：</th>
				<td>
					<input type="text" id="orderno" name="orderno"  class="easyui-numberbox"  style="width:300px;height:30px;"/>
				</td>
				<th>案件类型</th>
				<td>
					<input type="text" id="workflowtypeshare" name="workflowtype" class="easyui-combobox" style="width:300px;height:30px;"/>
				</td>
			</tr>
			<tr>
				<th>主文书：</th>
				<td><input type="text" id="wsnamenowpre"  class="easyui-combobox"  style="width:300px;height:30px;"/>
				<input type="hidden" id="wsnamenow" name="wsnamenow"  />
				<input type="hidden" id="wscodenow" name="wscodenow" />
				</td>
				<th>主文书列：</th>
				<td>
				<input type="text" id="wscolumenow" data-options='required:true, editable:false' name="wscolumenow" class="easyui-combobox"  style="width:300px;height:30px;"/>
				
				</td>
			</tr>
						<tr>
				<th>共享文书：</th>
				<td>
				<input type="text" id="wsnametopre" class="easyui-combobox"  style="width:300px;height:30px;"/>
                <input type="hidden" id="wsnameto" name="wsnameto" />
				<input type="hidden" name="wscodeto" id="wscodeto"/>
				</td>
				<th>共享文书列：</th>
				<td>
				<input type="text" id="wscolumnto" data-options='required:true, editable:false' name="wscolumnto" class="easyui-combobox"  style="width:300px;height:30px;"/>
				</td>
			</tr>

		</table>
	</form>
</div>


